package com.lovemanai.factory;

import java.lang.reflect.Field;

import org.springframework.beans.factory.FactoryBean;

//工厂bean
public class GetFieldFactoryBean implements FactoryBean<Object>{

	public String targetClass;
	public String targetField;
	
	
	public void setTargetClass(String targetClass) {
		this.targetClass = targetClass;
	}

	public void setTargetField(String targetField) {
		this.targetField = targetField;
	}
	
	//返回工厂bean生产的产品
	@Override
	public Object getObject() throws Exception {
		Class<?> clazz = Class.forName(targetClass);
		Field field = clazz.getField(targetField);
		return field.get(null);
	}

	//返回工厂bean所生产的产品类型
	@Override
	public Class<? extends Object> getObjectType() {
		return Object.class;
	}

	//返回工厂bean所生产的产品是否为单例
	@Override
	public boolean isSingleton() {
		return false;
	}

}
